package com.ruoyi.system.controller;

import java.util.List;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.mapper.FhStudentsInformationMapper;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.FhStudentsInformation;
import com.ruoyi.system.service.IFhStudentsInformationService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 学生基本信息Controller
 *
 * @author ruoyi
 * @date 2025-03-20
 */
@Controller
@RequestMapping("/system/information")
public class FhStudentsInformationController extends BaseController {
    private String prefix = "other/information";

    @Autowired
    private IFhStudentsInformationService fhStudentsInformationService;

    @Autowired(required = false)
    private FhStudentsInformationMapper fhStudentsInformationMapper;

    @RequiresPermissions("system:information:list")
    @GetMapping()
    public String information() {
        return prefix + "/StudentInformationList";
    }

    /**
     * 查询学生基本信息列表
     */
    @RequiresPermissions("system:information:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(FhStudentsInformation fhStudentsInformation) {

//        lap();

        startPage();
        Long deptId = fhStudentsInformation.getStuDeptId();
        if (StringUtils.isNotNull(deptId)) {
            if (deptId == 200) {
                fhStudentsInformation.setStuDeptId(null);
            }
        }
        List<FhStudentsInformation> list = fhStudentsInformationService.selectFhStudentsInformationList(fhStudentsInformation);
        return getDataTable(list);
    }

    /**
     * 导出学生基本信息列表
     */
    @RequiresPermissions("system:information:export")
    @Log(title = "学生基本信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FhStudentsInformation fhStudentsInformation) {
        List<FhStudentsInformation> list = fhStudentsInformationService.selectFhStudentsInformationList(fhStudentsInformation);
        ExcelUtil<FhStudentsInformation> util = new ExcelUtil<FhStudentsInformation>(FhStudentsInformation.class);
        return util.exportExcel(list, "学生基本信息数据");
    }

    /**
     * 新增学生基本信息
     */
    @RequiresPermissions("system:information:add")
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存学生基本信息
     */
    @RequiresPermissions("system:information:add")
    @Log(title = "学生基本信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FhStudentsInformation fhStudentsInformation) {
        return toAjax(fhStudentsInformationService.insertFhStudentsInformation(fhStudentsInformation));
    }

    /**
     * 修改学生基本信息
     */
    @RequiresPermissions("system:information:edit")
    @GetMapping("/edit/{stuId}")
    public String edit(@PathVariable("stuId") Long stuId, ModelMap mmap) {
        FhStudentsInformation fhStudentsInformation = fhStudentsInformationService.selectFhStudentsInformationByStuId(stuId);
        mmap.put("fhStudentsInformation", fhStudentsInformation);
        return prefix + "/edit";
    }

    /**
     * 修改保存学生基本信息
     */
    @RequiresPermissions("system:information:edit")
    @Log(title = "学生基本信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FhStudentsInformation fhStudentsInformation) {
        return toAjax(fhStudentsInformationService.updateFhStudentsInformation(fhStudentsInformation));
    }

    /**
     * 修改学生分组信息
     */
    @RequiresPermissions("system:information:editGroup")
    @GetMapping("/editGroup/{stuId}")
    public String editGroup(@PathVariable("stuId") Long stuId, ModelMap mmap) {
        FhStudentsInformation fhStudentsInformation = fhStudentsInformationService.selectFhStudentsInformationByStuId(stuId);
        mmap.put("fhStudentsInformation", fhStudentsInformation);
        return prefix + "/editGroup";
    }

    /**
     * 学生基本信息
     */
    @RequiresPermissions("system:information:detail")
    @GetMapping("/detail/{stuId}")
    public String detail(@PathVariable("stuId") Long stuId, ModelMap mmap) {
        FhStudentsInformation fhStudentsInformation = fhStudentsInformationService.selectFhStudentsInformationByStuId(stuId);
        mmap.put("fhStudentsInformation", fhStudentsInformation);
        return prefix + "/detail";
    }

    /**
     * 删除学生基本信息
     */
    @RequiresPermissions("system:information:remove")
    @Log(title = "学生基本信息", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(fhStudentsInformationService.deleteFhStudentsInformationByStuIds(ids));
    }

    /**
     * 根据id删除学生基本信息
     */
    @RequiresPermissions("system:information:removeById")
    @Log(title = "学生基本信息", businessType = BusinessType.DELETE)
    @PostMapping("/removeById")
    @ResponseBody
    public AjaxResult removeById(String ids) {
        return toAjax(fhStudentsInformationService.deleteFhStudentsInformationByStuId(Long.valueOf(ids)));
    }

    /**
     * 学生分组
     */
    @RequiresPermissions("system:information:getGroup")
    @PostMapping("/getGroupl/{ids}")
    @ResponseBody
    public AjaxResult getGroup(@PathVariable("ids") String ids) {
        return AjaxResult.success();
    }



    public void lap() {

        FhStudentsInformation studentsInformation = new FhStudentsInformation();
        List<FhStudentsInformation> list = fhStudentsInformationService.selectFhStudentsInformationList(studentsInformation);
        if(list.size() > 0) {

            for (FhStudentsInformation s : list) {
                studentsInformation.setStuId(s.getStuId());
                studentsInformation.setStuBirthday(s.getStuIdCard().substring(6,14));
                fhStudentsInformationMapper.updateFhStudentsInformation(studentsInformation);
            }
        }


    }
    public static void main(String[] args) {

    }

}
